﻿module Keywords



open Sources
open Tokens



type Keyword =
   | Feature 
   | Scenario 
   | Given 
   | When 
   | Then 



let IsKeyword(token : Token) =      
   match token.Source with   
   | "Feature:" | "Scenario:" | "Given:" | "When:" | "Then:" -> true
   | _ -> false



let ReadKeyword(reader : SourceReader, keyword : Keyword) =
   let token = ReadToken(reader)

   if (token.IsNone) then
      None
   else
      let source = token.Value.Source

      match keyword with   
      | Scenario when "Scenario:" = source -> token
      | Feature when "Feature:" = source -> token
      | Given when "Given:" = source -> token
      | When when "When:" = source -> token
      | Then when "Then:" = source -> token
      | _ -> None

   

let TryReadKeyword(reader : SourceReader, keyword : Keyword) =
   let location = reader.GetLocation()
   let result = 
      match ReadKeyword(reader, keyword) with
      | None -> false
      | _ -> true

   reader.SetLocation(location)
   result



